<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="标签模板编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
        	<p-input readonlyt disabled v-model="EnhanceJS.mcode" placeholder="标签模板编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标签模板名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readonly disabled v-model="EnhanceJS.mname" placeholder="请选择标签模板"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="打印份数 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number readonly disabled  v-model="EnhanceJS.prtintQty" :min="1" :trigger-change="true" dictCode="mes_filed_type" style="width: 100%" placeholder="请选择打印份数"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="本次打印份数 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   :min="1" :max="EnhanceJS.prtintQty" v-model="PrintingNumber" placeholder="请输入本次打印份数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
	
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction, putAction, api ,postActionBasic} from '@/api/manage'
  import pick from 'lodash.pick'
  import fSwitch from '@/components/switch'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import { mapState } from 'vuex'
  import moment from 'moment';

  export default {
    name: "MesBcFieldModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDictSelectTag,
      fSwitch,
    },
    props:{
      EnhanceJS:{
        type:String,
        required:false,
        default:''
      }
    },
    watch:{
      EnhanceJS(){
      }
    },
    computed:{
      ...mapState({
      userInfo:state => state.user,
    })
    },
    data () {
      return {
        number:1,
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        moment,
        PrintingNumber:1,
        confirmLoading: false,
        validatorRules:{
        filedCode:{rules: [{ required: true, message: '请输入字段编码!' }]},
        filedName:{rules: [{ required: true, message: '请输入字段名称!' }]},
        filedType:{rules: [{ required: true, message: '请输入字段属性!' }]},
        filedLength:{rules: [{ required: true, message: '请输入字段位数!' }]},
        barcodeBinary:{},
        filedCharacter:{rules: [{ required: true, message: '请输入字段字符!' }]},
        barcodeSource:{rules: [{ required: true, message: '请输入来源!' }]},
        filedSample:{rules: [{ required: true, message: '请输入字段示例!' }]},
        filedExplain:{},
        status:{},
        remark:{},
        },
        url: {
          add: '/mes-code/mesBcField',
          edit: '/mes-code/mesBcField',
          AddPrinting:"/mes-code/mesBcPrint"
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
      
        if(this.EnhanceJS && this.PrintingNumber){
          let data=this.getAddPrinting()
          postActionBasic(this.url.AddPrinting,data).then((res)=>{
            if(res.code==0){
              this.$message.success('提交成功');
              this.$emit('modalFormOk')
              var id = 'produceId='+this.EnhanceJS.getId; 
              var href = this.EnhanceJS.ureportAddress +"&"+ id; 
              // var href="http://192.168.6.145/fx-platform/ureport/preview?_u=mysql-%E5%B0%8F%E6%A0%87%E7%AD%BE%E6%B5%8B%E8%AF%95.ureport.xml&"+ id
              this.$router.push({
                path: `/layouts/IframePageRouter?=${href}`,
              })
              this.visible=false
            }else{
               this.$message.warning(res.msg);
            }
            
          })
        }else{
          this.$message.warning("请输入打印份数");
        }
       
    },
    // 提交打印记录数据
    getAddPrinting(){
      let aData = new Date();
       this.Data=aData.getFullYear() +"-" +(aData.getMonth() + 1) +"-" +aData.getDate()+" "+aData.getHours()+":"+aData.getMinutes()+":"+aData.getSeconds();
      let data={
         name: this.userInfo.name,//打印人
         qty:this.EnhanceJS.queryParam.qty,//打印份数
         labelTemplateName:this.EnhanceJS.labelTemplateName,//标签模板名称
         labelTemplateNo:this.EnhanceJS.labelTemplateNo,//标签模板编号
         productionno:this.EnhanceJS.active,//工单号
        ruleName:this.EnhanceJS.queryParam.barcodeRule,//条码规则名称
        beginBarcode:this.EnhanceJS.queryParam.firstBarcode,  //首标签条码
        endBarcode:this.EnhanceJS.queryParam.endBarcode,     //尾标签条码
        prtintQty:this.EnhanceJS.prtintQty
      }
      return data
    },
      handleCancel () {
        this.close()
      },

      
    }
  }
</script>
